package com.roc.web.action.excel;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class MerinfoSearchCondition extends BaseSearchCondition {

	private String  orgCode;//机构号
	private String[] agentId;//所属代理商
	private String merchantNo;//商户号
	private String merchantName;//商户名称
	private String  merBrName; //名称中文简称
	private String areaCode;//地区
	private String  cardNo; //身份证
	private String  mccName;//mcc
	private String merinfoChangeType;
	private String realName;
	private String merStatus;
	
	private String  midType;//商户类型

	public String getMidType() {
		return midType;
	}

	public void setMidType(String midType) {
		this.midType = midType;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	private String  addr;//商户地址
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if(Constance.isNotEmpty(merchantNo)){ //商户号
			filedBeanList.add(new WhereHQLFieldBean("et.mid", merchantNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(merchantName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("et.mer_name", merchantName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(merBrName)){ //商户名称 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("et.mer_br_name", merBrName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(areaCode)){ //地区
			if(!areaCode.equals("99")){
				filedBeanList.add(new WhereHQLFieldBean("em.area_code", areaCode.trim(), "=", false));
			}
			
		}
		if(Constance.isNotEmpty(cardNo)){ //法人身份证号
			filedBeanList.add(new WhereHQLFieldBean("em.card_no", cardNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(orgCode)&&!"99".equals(orgCode)){ //机构号
			filedBeanList.add(new WhereHQLFieldBean("et.belong_branch", orgCode.trim(), "=", false));
		}
		if(Constance.isNotEmpty(mccName)){//mcc
			filedBeanList.add(new WhereHQLFieldBean("et.mcc", mccName.trim(), "=", false));
		}
		
		if(Constance.isNotEmpty(midType)&&!"99".equals(midType)){ //商户类型
			filedBeanList.add(new WhereHQLFieldBean("et.MER_KIND", midType.trim(), "=", false));
		}
		if(Constance.isNotEmpty(addr)){ //商户地址 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("et.addr", addr.trim(), "like", false,"ALL"));
		}
		if(agentId!=null&&agentId.length >0){//代理商
	        	filedBeanList.add(new WhereHQLFieldBean("em.agent_id IN("+Constance.getArrayContent(agentId)+")"));
	    }
		if(Constance.isNotEmpty(realName)){ //所属代理商 （模糊）
			filedBeanList.add(new WhereHQLFieldBean("o.REAL_NAME", realName.trim(), "like", false,"ALL"));
		}
		if(Constance.isNotEmpty(merStatus)&&!"99".equals(merStatus)){ //商户类型
			filedBeanList.add(new WhereHQLFieldBean("et.MER_STATUS", merStatus.trim(), "=", false));
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		// TODO Auto-generated method stub
		//return "select count(*) from EsmidinfoTmp et,EsmidinfoMerinfo em where et.mid=em.merchant and et.flag=1";
		return " select count(*) from esmidinfo_tmp et,esmidinfo_tmp_merinfo em ,t_operators o where et.mid=em.merchant  and o.id=em.agent_id ";
	}

	@Override
	protected String getSearchHQL() {
		// TODO Auto-generated method stub
		//return "from EsmidinfoTmp et,EsmidinfoMerinfo em where et.mid=em.merchant and et.flag=1";
		String  sql="SELECT et.mid,et.mer_name,et.mer_br_name,et.mer_kind,et.flag ,      "
				+"et.rsv1,et.rsv3,et.inter_contact,em.peraonal_phone,em.personal_name,  "
				+"em.cycleid,em.card_type,em.card_no,et.addr,em.area_code,em.agent_id, "
				+"et.COMM_RATE,et.COMM_MODE,et.comm_amt,em.BUSINESS_LICENCES,em.AMOUNT1,em.AMOUNT2,em.DAY_TOTAL_AMT1," 
				+"em.DAY_TOTAL_AMT2 ,em.MONTH_TOTAL_AMT1,em.MONTH_TOTAL_AMT3,et.SETTIME,et.ENG_NAME,et.ENG_BR_NAME,et.MCC,o.real_name,et.MER_STATUS  "
				+"FROM esmidinfo_tmp et,esmidinfo_tmp_merinfo em,t_operators o   "
				+"WHERE et.mid=em.merchant and o.id=em.agent_id ";
		return sql;
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return "order by em.dt_Create DESC";
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}


	public String[] getAgentId() {
		return agentId;
	}

	public void setAgentId(String[] agentId) {
		this.agentId = agentId;
	}

	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getMerchantName() {
		return merchantName;
	}

	public void setMerchantName(String merchantName) {
		this.merchantName = merchantName;
	}

	public String getMerBrName() {
		return merBrName;
	}

	public void setMerBrName(String merBrName) {
		this.merBrName = merBrName;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getMccName() {
		return mccName;
	}

	public void setMccName(String mccName) {
		this.mccName = mccName;
	}

	public String getMerinfoChangeType() {
		return merinfoChangeType;
	}

	public void setMerinfoChangeType(String merinfoChangeType) {
		this.merinfoChangeType = merinfoChangeType;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getMerStatus() {
		return merStatus;
	}

	public void setMerStatus(String merStatus) {
		this.merStatus = merStatus;
	}
	
	

}
